package hongcheng.code_generator.entity.config;

import hongcheng.code_generator.enumeration.DbNameEnum;
import hongcheng.code_generator.exception.CustomException;

/**
 * 	模板文件地址配置类
 * */
public class TempletFileConfig {

	private String controllerTplPath = "template/controller/controller.ftl";
	private ResourceMode controllerTplResourceMode = ResourceMode.CLASSPATH;
	private String serviceTplPath = "template/service/service.ftl";
	private ResourceMode serviceTplResourceMode = ResourceMode.CLASSPATH;
	private String serviceImplTplPath = "template/service/serviceImpl.ftl";
	private ResourceMode serviceImplTplResourceMode = ResourceMode.CLASSPATH;
	private String daoTplPath = "template/dao/dao.ftl";
	private ResourceMode daoTplResourceMode = ResourceMode.CLASSPATH;
	private String entityTplPath = "template/entity/entity.ftl";
	private ResourceMode entityTplResourceMode = ResourceMode.CLASSPATH;
	private String xmlTplPath = "template/mapper/mysql/mysqlMapper.ftl";
	private ResourceMode xmlTplResourceMode = ResourceMode.CLASSPATH;
	private String queryVOTplPath = "template/queryvo/queryVo.ftl";
	private ResourceMode queryVOTplResourceMode = ResourceMode.CLASSPATH;
	
	/**
	 * 资源加载方式枚举
	 */
	public enum ResourceMode {
		/** 从ClassPath加载模板 */
		CLASSPATH("CLASSPATH"),
		/** 从File目录加载模板 */
		FILE("FILE"),
		/** 从WebRoot目录加载模板 */
		WEB_ROOT("WEB_ROOT"),
		/** 从模板文本加载模板 */
		STRING("STRING");
		
		private String mode;
		private ResourceMode(String mode) {
			this.mode = mode;
		}
		
		public static ResourceMode fromString(String mode) {
			for(ResourceMode rm :ResourceMode.values()) {
				if(rm.mode.equals(mode)) {
					return rm;
				}
			}
			throw new CustomException("ResourceMode中找不到"+mode);
		}
	}
	
	
	public String getQueryVOTplPath() {
		return queryVOTplPath;
	}
	public void setQueryVOTplPath(String queryVOTplPath) {
		this.queryVOTplPath = queryVOTplPath;
	}
	public ResourceMode getQueryVOTplResourceMode() {
		return queryVOTplResourceMode;
	}
	public void setQueryVOTplResourceMode(ResourceMode queryVOTplResourceMode) {
		this.queryVOTplResourceMode = queryVOTplResourceMode;
	}
	public String getControllerTplPath() {
		return controllerTplPath;
	}
	public void setControllerTplPath(String controllerTplPath) {
		this.controllerTplPath = controllerTplPath;
	}
	public String getServiceTplPath() {
		return serviceTplPath;
	}
	public void setServiceTplPath(String serviceTplPath) {
		this.serviceTplPath = serviceTplPath;
	}
	public String getServiceImplTplPath() {
		return serviceImplTplPath;
	}
	public void setServiceImplTplPath(String serviceImplTplPath) {
		this.serviceImplTplPath = serviceImplTplPath;
	}
	public String getDaoTplPath() {
		return daoTplPath;
	}
	public void setDaoTplPath(String daoTplPath) {
		this.daoTplPath = daoTplPath;
	}
	public String getEntityTplPath() {
		return entityTplPath;
	}
	public void setEntityTplPath(String entityTplPath) {
		this.entityTplPath = entityTplPath;
	}
	public String getXmlTplPath() {
		return xmlTplPath;
	}
	public void setXmlTplPath(String xmlTplPath) {
		this.xmlTplPath = xmlTplPath;
	}
	
	public ResourceMode getControllerTplResourceMode() {
		return controllerTplResourceMode;
	}
	public void setControllerTplResourceMode(ResourceMode controllerTplResourceMode) {
		this.controllerTplResourceMode = controllerTplResourceMode;
	}
	public ResourceMode getServiceTplResourceMode() {
		return serviceTplResourceMode;
	}
	public void setServiceTplResourceMode(ResourceMode serviceTplResourceMode) {
		this.serviceTplResourceMode = serviceTplResourceMode;
	}
	public ResourceMode getServiceImplTplResourceMode() {
		return serviceImplTplResourceMode;
	}
	public void setServiceImplTplResourceMode(ResourceMode serviceImplTplResourceMode) {
		this.serviceImplTplResourceMode = serviceImplTplResourceMode;
	}
	public ResourceMode getDaoTplResourceMode() {
		return daoTplResourceMode;
	}
	public void setDaoTplResourceMode(ResourceMode daoTplResourceMode) {
		this.daoTplResourceMode = daoTplResourceMode;
	}
	public ResourceMode getEntityTplResourceMode() {
		return entityTplResourceMode;
	}
	public void setEntityTplResourceMode(ResourceMode entityTplResourceMode) {
		this.entityTplResourceMode = entityTplResourceMode;
	}
	public ResourceMode getXmlTplResourceMode() {
		return xmlTplResourceMode;
	}
	public void setXmlTplResourceMode(ResourceMode xmlTplResourceMode) {
		this.xmlTplResourceMode = xmlTplResourceMode;
	}
	/**
	 * 	目前只有MySQL数据库有模板文件，其他数据库没有
	 * */
	public void setXmlTplPathByDBName(DbNameEnum dbName) {
		if(dbName == DbNameEnum.MYSQL) {
			this.xmlTplPath = "template/mapper/mysql/mysqlMapper.ftl";
			this.xmlTplResourceMode = ResourceMode.CLASSPATH;
		}else if(dbName == DbNameEnum.ORACLE) {
			this.xmlTplPath = "template/mapper/oracle/oracleMapper.ftl";
			this.xmlTplResourceMode = ResourceMode.CLASSPATH;
		}else if(dbName == DbNameEnum.SQL_SERVER) {
			throw new CustomException("系统中不存在该数据库{}的xmlMapper.ftl模板" , dbName.toString()) ;
		}else {
			throw new CustomException("系统中不存在该数据库名：" + dbName);
		}
	}
}
